package com.cowealth.platform.common.base.util;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * URL 解码/编码工具类
 *
 * @author      : skycdm
 * @date        : 2020/7/24 16:50
 * @version     : 1.0.0
 */
public class EnDecoderUtils {

    /**
     * 字符串进行URL编码
     * @param str
     * @return
     */
    public static String encoder(String str) {
        try {
            String enc = URLEncoder.encode(str, "utf-8");
            return enc;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }

    /**
     * 字符串进行URL解码
     * @param str
     * @return
     */
    public static String decoder(String str) {
        try {
            String dec = URLDecoder.decode(str, "utf-8");
            return dec;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }
}
